package com.ysd.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.Newscategory;
import com.ysd.utli.DBManager;
public class NewscategoryDaolmpl {
	public List<Newscategory> getNewscategory() {
		List<Newscategory> list = new ArrayList<Newscategory>();
		Connection conn = DBManager.getConnection();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			String sql = "select * from newscategory";//��ѯ������Ѷ����
			rs = st.executeQuery(sql);
			while(rs.next()) {
				int newsCategoryid = rs.getInt("newsCategoryid");
				String newsCategoryName = rs.getString("newsCategoryName");
				Newscategory newscatsegory = new Newscategory(newsCategoryid, newsCategoryName);
				list.add(newscatsegory);
			}
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
	/**
	 * 根据产品分类id删除产品分类
	 * @param id 分类id
	 * @return 数据库受影响行数
	 */
	public int delCateoryId(int delId) {
		return DBManager.executeUpdate("DELETE FROM newscategory WHERE newsCategoryid="+delId);
	}
}


